package com.dream.base.web.provider.impl;

import java.util.Date;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dream.app.service.AppAccessLogService;
import com.dream.model.app.AppAccessLog;
import com.dream.utils.annotation.AccessLog;
import com.dream.utils.log.DreamLogUtils;
import com.dream.utils.web.provider.AccessLogProvider;

/**
 * @copyright evan
 * @author evan
 * @Revision
 * @date 2013/8/29
 */
@Service("accessLogProvider")
public class AppAccessLogProviderImpl implements AccessLogProvider {

	@Autowired
	private AppAccessLogService appAccessLogService;
	
	@Override
	@Transactional
	public void accesslog(AccessLog accessLog, Map<String, String> requestInfo,Map<String,Date> accessMap) {
		
		AppAccessLog log = new AppAccessLog();
		log.setIp(requestInfo.get("ip="));
		log.setUri(requestInfo.get("path="));
		
		log.setClassName(requestInfo.get("class="));
		log.setMethodName(requestInfo.get("method="));
		
		log.setStartTime(accessMap.get("start_time="));
		log.setEndTime(accessMap.get("end_time="));
		
		log.setUserId(requestInfo.get("userId="));
		log.setUserName(requestInfo.get("userName="));
		
		log.setModule(accessLog.module());
		log.setContent(accessLog.content());
		
		appAccessLogService.record(log);
		DreamLogUtils.accessInfo(log.toString());
	}

}
